﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WebSocket4Net;
using System.Threading;

namespace Client
{
    public partial class CFrmMain : Form
    {
        WebSocket websocket ;
            
        public CFrmMain()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            WebSocketHelper.Instance.MessageResult += new WebSocketHelper.MessageEventHandler(ShowMessage);
        }

        private void ShowMessage(object sender, MessageEventArgs e)
        {
            if (!this.IsHandleCreated || IsDisposed)
            {
                return;
            }

            listBox1.Invoke(new EventHandler(delegate
            {
                this.listBox1.Items.Add(e.Result);
            }));

            
        }

         private void button1_Click(object sender, EventArgs e)
         {
             WebSocketHelper.Instance.Start(textBox1.Text, textBox2.Text);
         }

         private void button2_Click(object sender, EventArgs e)
         {
             WebSocketHelper.Instance.Send(textBox1.Text + ":" + textBox2.Text + "发送：" + textBox3.Text);
         }
    }
}
